package org.vectrics.graphics;

import org.apache.ecs.html.IMG;
import org.vectrics.common.http.HttpUtils;
import org.vectrics.struts.VectricsTagSupport;

/**
 * @author mmoore
 */
public class DynaGraphicTag extends VectricsTagSupport {

	private static final long serialVersionUID = -2026785632205942116L;
	
	private String code = null;
    private String caption = null;
	private String width = null;
    private String height = null;
    private String alt = null;
    private String id = null;
    
    /**
     * 
     */
    public DynaGraphicTag() {
        super();

    }

    //<input type="image" src="//www.ibm.com/i/v11/m/en/search.gif" width="64" height="23" border="0" value="Search" name="Search" alt="Search" id="Search" />    
    
    protected String makeStartTag() {
        String imageSource = "dynagraphic/" + code + ".jpg?code=" + code;
        
        if (caption != null) {
            imageSource += "&caption=" + HttpUtils.encodeHttpQueryValue(caption);
        }
        
        IMG img = new IMG();
        img.setSrc(imageSource);
        if (this.getId() != null) {
            img.addAttribute("id", this.getId());
        } else {
        	String uniqueId = "" + this.getCaption().hashCode() + "-" + this.getCode().hashCode();
            img.addAttribute("id", uniqueId);
//        	img.setID("img_" + code);
        }
        
        if (this.getAlt() != null)
        	img.setAlt(this.getAlt());
        if (this.getWidth() != null)
        	img.setWidth(this.getWidth());
        if (this.getHeight() != null)
        	img.setHeight(this.getHeight());
        
        return(img.toString());
    }

    /**
     * @return Returns the code.
     */
    public String getCode() {
        return code;
    }
    
    /**
     * @param code The code to set.
     */
    public void setCode(String code) {
        this.code = code;
    }
    
    
    /**
     * @return Returns the caption.
     */
    public String getCaption() {
        return caption;
    }
    /**
     * @param caption The caption to set.
     */
    public void setCaption(String caption) {
        this.caption = caption;
    }

	/**
	 * @return Returns the alt.
	 */
	public String getAlt() {
		return alt;
	}

	/**
	 * @param alt The alt to set.
	 */
	public void setAlt(String alt) {
		this.alt = alt;
	}

	/**
	 * @return Returns the height.
	 */
	public String getHeight() {
		return height;
	}

	/**
	 * @param height The height to set.
	 */
	public void setHeight(String height) {
		this.height = height;
	}

	/**
	 * @return Returns the width.
	 */
	public String getWidth() {
		return width;
	}

	/**
	 * @param width The width to set.
	 */
	public void setWidth(String width) {
		this.width = width;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
    
    
}
